package com.liu.dao.role;

import com.liu.dao.BaseDao;
import com.liu.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoimpl implements RoleDao{
    @Override
    public List<Role> getRoleList(Connection connection) throws SQLException {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        ArrayList<Role> roles = new ArrayList<Role>();
        if (connection != null){
            String sql = "select * from smbms_role";
            Object[] params = {};
            ResultSet st = BaseDao.execute(connection, pstm, rs, sql, params);

            while(st.next()){
                Role _role = new Role();
                _role.setId(st.getInt("id"));
                _role.setRoleCode(st.getString("roleCode"));
                _role.setRoleName(st.getString("roleName"));
                roles.add(_role);
            }
            BaseDao.closeResource(null, pstm, rs);
        }
        return roles;
    }
}
